
// OKR子任务进展
var childrenColumns = [{
  id: 'zhouqi',
  title: '项目目标',
  width: 100,
  type: 'string',
  columnClass: 'text-left',
}, {
  id: 'mubiao',
  title: '阶段目标',
  type: 'string',
  width: 100,
  columnClass: 'text-left',
}, {
  id: 'renwu',
  title: '标准任务',
  type: 'string',
  width: 100,
  columnClass: 'text-left',
}, {
  id: 'chengguo',
  title: '关键成果',
  type: 'string',
  width: 100,
  columnClass: 'text-left',
}, {
  id: 'planTime',
  title: '计划完成时间',
  type: 'string',
  width: 100,
  columnClass: 'text-center',
}, {
  id: 'kr',
  title: 'KR权重',
  type: 'string',
  width: 70,
  columnClass: 'text-center',
}, {
  id: 'user',
  title: '成员',
  type: 'string',
  width: 75,
  columnClass: 'text-center',
}, {
  id: 't100',
  title: '投入百分比',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'krover',
  title: 'KR完成率',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'e100',
  title: '实际投入百分比',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'domsg',
  title: '子任务进展',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'nextmsg',
  title: '下一步计划',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'krp',
  title: 'KR得分',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'op',
  title: 'O得分',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'time',
  title: '更新时间',
  type: 'string',
  columnClass: 'text-center',
  hideType: 'xs|sm|md|lg',
}, {
  id: 'operation',
  title: '操作',
  width: 180,
  type: 'string',
  columnClass: 'text-center',
  resolution: function (value, record, column, grid, dataNo, columnNo) {
    var content = '';
    content += '<button class="btn btn-xs btn-success" onclick="rechildren(' + record.id + ');"><i class="icon-refresh"></i>  更新</button>';
    content += '  ';
    content += '<button class="btn btn-xs btn-info" onclick=""><i class="fa fa-edit"></i>  编辑</button>';
    content += '  ';
    content += '<button class="btn btn-xs btn-danger" onclick="del(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
    return content;
  }
}];
var childrenOption = {
  lang: 'zh-cn',
  ajaxLoad: false,
  // loadURL:'url',
  exportFileName: 'OKR子任务进展',
  datas: [{
    id: 1,
    zhouqi: '测试数据',
    mubiao: '测试数据',
    renwu: '测试数据',
    chengguo: '测试数据',
    planTime: '2018-06-10',
    kr: '25%',
    user: '张三测试',
    t100: '100%',
    krover: '20%',
    e100: '34%',
    domsg: '子任务进展测试数据',
    nextmsg: '下一步计划测试数据',
    krp: '20分',
    op: '30分',
    time: '2018-06-10',
  }, {
    id: 2,
    zhouqi: '测试数据',
    mubiao: '测试数据',
    renwu: '测试数据',
    chengguo: '测试数据',
    planTime: '2018-06-10',
    kr: '25%',
    user: '张三测试',
    t100: '100%',
    krover: '20%',
    e100: '34%',
    domsg: '子任务进展测试数据',
    nextmsg: '下一步计划测试数据',
    krp: '20分',
    op: '30分',
    time: '2018-06-10',
  }, {
    id: 3,
    zhouqi: '测试数据',
    mubiao: '测试数据',
    renwu: '测试数据',
    chengguo: '测试数据',
    planTime: '2018-06-10',
    kr: '25%',
    user: '张三测试',
    t100: '100%',
    krover: '20%',
    e100: '34%',
    domsg: '子任务进展测试数据',
    nextmsg: '下一步计划测试数据',
    krp: '20分',
    op: '30分',
    time: '2018-06-10',
  }, ],
  columns: childrenColumns,
  gridContainer: 'childrenContainer',
  toolbarContainer: 'childrenToolBarContainer',
  tools: '',
  pageSize: 10,
  pageSizeLimit: [10, 15, 20]
};
var childrenGrid = $.fn.dlshouwen.grid.init(childrenOption);
$(function () {
  childrenGrid.load();
});
// 子任务数据更新
function rechildren(id) {
  location.href = './edit-children.html';
}


var dataJson = {
  "option": [{
    "id": "1",
    "name": "战略类项目标准动作",
    "child": [{
      "id": "4",
      "name": "OKR推行",
      "child": [{
        "id": "12",
        "name": "每个季度OKR辅导"
      },{
        "id": "13",
        "name": "测试数据"
      }]
    }]
  }]
}
var l1 = 0,
  l2 = 0;
var cname1, cname2, cname3;
var cid1, cid2, cid3;
var canClick = !0;
var canClose = !1;
$('.select-box').css({
  left: $('.select-res').offset().left,
  top: $('.select-res').offset().top + $('.select-res').outerHeight(true)
});
$('span', $('.select-res')).on('click', function () {
  $('.select-box').show();
  if (canClick) {
    $('ul', $('.select-box')).html('');
    fillData();
    canClick = !1;
  }
});
$('span', $('.select-box')).on("click", function () {
  canClose ? $('.select-box').hide() : layer.msg('请选择下级类目！');
  canClick = !0;
});

$('.select-res').on('click', 'a', function () {
  $(this).parent().remove();
  $('.select-box').css({
    top: $('.select-res').offset().top + $('.select-res').outerHeight(true)
  });
})

$('ul.first', $('.select-box')).on('click', 'li', function () {
  $(this).addClass('selected').siblings().removeClass('selected');
  $('ul.third').html('');
  fillData($(this).index());
  l1 = $(this).index();
  cname1 = $(this).text();
  cid1 = $(this).attr('val');
  canClose = !1;
  $('input.cid', $('.select-res')).val(cid1);
  $('input.cname', $('.select-res')).val(cname1);
});
$('ul.second', $('.select-box')).on('click', 'li', function () {
  $(this).addClass('selected').siblings().removeClass('selected');
  fillData(l1, $(this).index());
  l2 = $(this).index();
  cname2 = $(this).text();
  cid2 = $(this).attr('val');
  canClose = !1;
  $('input.cid', $('.select-res')).val(cid1 + ',' + cid2);
  $('input.cname', $('.select-res')).val(cname1 + ',' + cname2);
});
$('ul.third', $('.select-box')).on('click', 'li', function () {
  $(this).addClass('selected').siblings().removeClass('selected');
  cname3 = $(this).text();
  cid3 = $(this).attr('val');
  canClose = !0;
  var hasExist = !1;
  $('.select-res').find("p").each(function () {
    if ($(this).text().split(' > ')[2] == cname3) hasExist = !0;
  })
  hasExist ? layer.msg('所选类目已被添加！') : $('.select-res span').text(cname1 + ' > ' + cname2 + ' > ' + cname3);
  $('.select-box').css({
    top: $('.select-res').offset().top + $('.select-res').outerHeight(true)
  });
  $('input.cid', $('.select-res')).val(cid1 + ',' + cid2 + ',' + cid3);
  $('input.cname', $('.select-res')).val(cname1 + ',' + cname2 + ',' + cname3);
});

//填充级联数据
function fillData(l1, l2) {
  var temp_html = "";
  if (typeof (dataJson.option) != 'undefined' && arguments.length == 0) {
    $.each(dataJson.option, function (i, pro) {
      temp_html += '<li val="' + pro.id + '">' + pro.name + '</li>';
    });
  } else if (typeof (dataJson.option[l1].child) != 'undefined' && arguments.length == 1) {
    $.each(dataJson.option[l1].child, function (i, pro) {
      temp_html += '<li val="' + pro.id + '">' + pro.name + '</li>';
    });
  } else if (typeof (dataJson.option[l1].child[l2].child) != 'undefined' && arguments.length == 2) {
    $.each(dataJson.option[l1].child[l2].child, function (i, pro) {
      temp_html += '<li val="' + pro.id + '">' + pro.name + '</li>';
    });
  }
  $('.select-box ul:eq(' + arguments.length + ')').html(temp_html);
}


$('#dotype').on('change',function(){
  var th = $(this);
  var vals = th.val();
  if(vals==0){
    $('.renbox').hide();
    $('.mubox').show();
  }else{
    $('.renbox').show();
    $('.mubox').hide();
  }
});


// 模板信息
var treeColumns = [{
  id: 'dotype',
  title: '动作类型',
  width: 200,
  type: 'string',
  columnClass: 'text-center',
}, {
  id: 'mubiao',
  title: '阶段目标',
  width: 200,
  type: 'string',
  columnClass: 'text-center',
}, {
  id: 'renwu',
  title: '标准任务',
  width: 200,
  type: 'string',
  columnClass: 'text-center',
}, {
  id: 'operation',
  title: '操作',
  width: 100,
  type: 'string',
  columnClass: 'text-center',
  resolution: function (value, record, column, grid, dataNo, columnNo) {
    var content = '';
    content += '<button class="btn btn-xs btn-info" onclick=""><i class="fa fa-edit"></i>  编辑</button>';
    content += '  ';
    content += '<button class="btn btn-xs btn-danger" onclick="del(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
    return content;
  }
}];
var treeOption = {
  lang: 'zh-cn',
  ajaxLoad: false,
  // loadURL:'url',
  exportFileName: '模板标准库',
  datas: [{
    id: 1,
    dotype: '战略类项目标准动作',
    mubiao: '阶段目标测试数',
    renwu: '标准任务测试数',
  },],
  columns: treeColumns,
  gridContainer: 'treeContainer',
  toolbarContainer: 'treeToolBarContainer',
  tools: '',
  pageSize: 10,
  pageSizeLimit: [10, 15, 20]
};
var treeGrid = $.fn.dlshouwen.grid.init(treeOption);
$(function () {
  treeGrid.load();
});

$('#datetime').datepicker({
  format: 'yyyy-mm-dd'
});